//
//  myOdderCell.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/5/22.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "myOdderCell.h"
#import "myCoach.h"
#import "confirmView.h"
#import "PaymentFullVC.h"
@implementation myOdderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.myCoach_btn.layer.masksToBounds = YES;
    self.myCoach_btn.layer.cornerRadius = 10;
    self.myCoach_btn.layer.borderColor = [UIColor custom_color:@"#A91E23"].CGColor;
    self.myCoach_btn.layer.borderWidth = 1;
    
    self.checkDetails_btn.layer.masksToBounds = YES;
    self.checkDetails_btn.layer.cornerRadius = 11;
    self.checkDetails_btn.layer.borderColor = [UIColor custom_color:@"#A91E23"].CGColor;
    self.checkDetails_btn.layer.borderWidth = 1;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)myCoachClick:(UIButton *)sender {
    if ([sender.titleLabel.text isEqualToString:@"我的教练"]) {
        myCoach *VC = [myCoach new];
        VC.ID = _model.id;
        [[helpPublic getCurrentViewController:self].navigationController pushViewController:VC animated:YES];
    }else if ([sender.titleLabel.text isEqualToString:@"去付款"]) {//全额支付 分期不会在这里支付
        PaymentFullVC *VC = [PaymentFullVC new];
        VC.ID = _model.id;
        VC.driveID = _model.agencyId;
        VC.money = _model.price;
        [[helpPublic getCurrentViewController:self].navigationController pushViewController:VC animated:YES];
    }
}
- (IBAction)checkDetial:(id)sender {//支付服务费
    [self pay:@"1"];
}
- (void)setModel:(orderListModel *)model {
    _model = model;
    self.noNumber_lab.text = _model.oid;
    self.picture_lab.text = [NSString stringWithFormat:@"%@元", _model.price];
    self.date_lab.text = [NSString ConvertStrToTime:_model.createDate];
    if ([_model.divides isEqualToString:@"0"] || _model.divides == nil) {
        self.installment_lab.text = [NSString stringWithFormat:@""];
    }else {
        self.installment_lab.text = [NSString stringWithFormat:@"分%@期(%@手续费) %@元/期", _model.divides, _model.interest, _model.repayMoney];
    }
    self.name_lab.text = _model.name;
    [self.picture_imgV sd_setImageWithURL:[NSURL URLWithString:_model.img] placeholderImage:[UIImage imageNamed:@"photo"]];
    self.myCoach_btn.hidden = YES;
    self.checkDetails_btn.hidden = YES;
    if ([_model.orderStatus isEqualToString:@"0"]) {
        self.status_lab.text = @"待审核";
        self.status_lab.textColor= [UIColor custom_color:@"#666666"];
    }else if ([_model.orderStatus isEqualToString:@"1"]) {
        self.status_lab.text = @"待支付服务费";
        self.status_lab.textColor = [UIColor custom_color:@"#E69D24"];
        self.checkDetails_btn.hidden = NO;
        [self.checkDetails_btn setTitle:@"支付服务费" forState:0];
    }else if ([_model.orderStatus isEqualToString:@"2"]) {
        self.status_lab.text = @"审核失败";
        self.status_lab.textColor= [UIColor custom_color:@"#A91E23"];
    }else if ([_model.orderStatus isEqualToString:@"3"]) {
        self.status_lab.text = @"待分配教练";
        self.status_lab.textColor= [UIColor greenColor];
    }else if ([_model.orderStatus isEqualToString:@"4"]) {
        self.status_lab.text = @"待支付";
        self.status_lab.textColor= [UIColor custom_color:@"#E69D24"];
        self.myCoach_btn.hidden = NO;
        [self.myCoach_btn setTitle:@"去付款" forState:0];
    }else if ([_model.orderStatus isEqualToString:@"5"]) {
        self.status_lab.text = @"成功";
        self.status_lab.textColor= [UIColor custom_color:@"#6AB46C"];
    }else if ([_model.orderStatus isEqualToString:@"6"]) {
        self.status_lab.text = @"已分配教练";
        self.status_lab.textColor= [UIColor custom_color:@"#4197F3"];
        self.myCoach_btn.hidden = NO;
        [self.myCoach_btn setTitle:@"我的教练" forState:0];
    }else if ([_model.orderStatus isEqualToString:@"7"]) {
        self.status_lab.text = @"学完";
        self.status_lab.textColor= [UIColor custom_color:@"#A91E23"];
    }
}
- (void)pay:(NSString *)type {//1-服务费 2付款
    confirmView *View = [[NSBundle mainBundle] loadNibNamed:@"confirmView"owner:self options:nil].firstObject;
    View.ID = _model.id;
    View.money_lab.text = [NSString stringWithFormat:@"%.2f", _model.serviceMoney.doubleValue];
    View.order_lab.text = _model.oid;
    if ([type isEqualToString:@"1"]) {// 服务费z
        View.payType = type;
        View.payMoney = _model.serviceMoney;
    }
    [helpPublic getCurrentViewController:self].definesPresentationContext = YES;
    UIViewController *vc = [[UIViewController alloc]init];
    vc.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
    vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [vc.view addSubview:View];
    [View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.bottom.equalTo(@0);
        make.height.equalTo(@343);
    }];
    [self.window.rootViewController presentViewController:vc animated:YES completion:nil];
}
@end
